<?php

class Kpl_Action_Helper_User extends Zend_Controller_Action_Helper_Abstract {

	private $_auth = null;

	private function _auth() {
		return Zend_Auth::getInstance();
	}

	public function getInfo()
	{
		if ($user = $this->_auth()->getIdentity())
		{
			$user->tty = 'tty4';
			return $user;
		}
		else return false;
	}

	public function getRoles()
	{

		if ($user =  $this->_auth()->getIdentity())
			return $user->roles;
		else return array();
	}


	public function getCurrentGroup() {

		if ((count(($this->getRoles())) > 0) && is_array($this->getRoles()) ) {
			if (isset($_SESSION['chosengroup'])) {
				return $_SESSION['chosengroup'];
			} else {
				$roles = $this->getRoles();
				return $roles[0];
			}
		} else return false;
	}

	public function setCurrentGroup($groupname) {
		if (in_array($groupname,$this->getRoles()))
			$_SESSION['chosengroup'] = $groupname;
	}
	
	public function clearCurrentGroup() {
		unset($_SESSION['chosengroup']);
	}
}